package com.work.customer.listener;

import com.alibaba.fastjson.JSON;
import com.work.customer.config.RabbitmqConfig;
import com.work.customer.pojo.CustUser;
import com.work.customer.pojo.Customer;
import com.work.customer.service.CustUserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


//@Component
public class CustomerListener {

    @Autowired
    private CustUserService custUserService;

    //更改平台用户状态
    @RabbitListener(queues = RabbitmqConfig.CUSTOMER_QUEUE)
    public void update(String message){
        Customer customer = JSON.parseObject(message, Customer.class);
        //通过农场组织id查询平台超级管理员
        CustUser custUser = custUserService.findByCustomerId(customer.getId());
        //修改平台超级管理员状态与农场组织一致
        custUser.setStatus(customer.getStatus());
        custUserService.update(custUser);
    }

}
